package cn.com.nes.site.controller.crm.clue;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.site.controller.crm.clue.vo.CluePageVo;
import cn.com.nes.site.controller.crm.clue.vo.ClueSaveVO;
import cn.com.nes.site.entity.vo.crm.GetClueDetailVO;
import cn.com.nes.site.entity.vo.crm.SaveUpdateClueVo;
import cn.com.nes.site.service.crm.clue.CrmClueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = {"销售管理-线索管理"})
@Controller
@RequestMapping("/v2/crm/clue")
public class ClueController {

    @Resource
    private CrmClueService crmClueService;

    @ApiOperation("线索列表分页")
    @RequestMapping(value = "/getClueListPage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<?> getClueListPage(@Validated CluePageVo vo) throws Exception {
        return CommonResult.page(crmClueService.getCluePage(vo));
    }

    @ApiOperation("保存线索")
    @RequestMapping(value = "/saveClue", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> saveClue(@RequestBody @Validated ClueSaveVO vo) throws Exception {
         return CommonResult.data(crmClueService.clueSave(vo.convertToBo()).getUuid());
    }

    @ApiOperation("新增修改线索")
    @RequestMapping(value = "/saveUpdateClue", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> saveUpdateClue(@RequestBody @Validated SaveUpdateClueVo vo) throws Exception {
        return CommonResult.data("id", crmClueService.saveUpdateClue(vo));
    }

    @ApiOperation("查询线索详情")
    @RequestMapping(value = "/getClueDetail", method = RequestMethod.GET)
    public @ResponseBody CommonResult<?> getClueDetail(@Validated GetClueDetailVO vo) throws Exception {
        return CommonResult.data(crmClueService.getClueDetail(vo));
    }

}
